package com.java46.carera.staff;

import com.java46.carera.base.entity.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class StaffController {
    @Autowired
    private StaffService staffService;

    // 添加
    @RequestMapping("/addStaff")
    public String addStaff(String staff_name, String staff_sex, Integer staff_department, Integer staff_position,
                            String staff_cell_phone_number, String staff_id_number){
       staffService.addStaff(staff_name, staff_sex,staff_department,staff_position,staff_cell_phone_number,staff_id_number);
        return "staff/staff";
    }

    // 分页查询
    @RequestMapping("/selectStaffAll")
    @ResponseBody
    public JsonResult selectStaffAll(Integer pagenNum, String keyword){
        JsonResult jsonResult = staffService.selectStaffAll(pagenNum, keyword);
        return jsonResult;
    }

    // 查询所有
    @RequestMapping("/Staff/selectAll")
    @ResponseBody
    public JsonResult selectStaffAll(){
        JsonResult jsonResult = staffService.selectAll();
        return jsonResult;
    }

    // 修改前的查询
    @RequestMapping(value = "/selectStaff",  produces = "application/json;charset=utf-8")
    @ResponseBody
    public JsonResult selectStaff(Integer staff_id){
        JsonResult jsonResult = staffService.selectStaff(staff_id);
        return jsonResult;
    }

    // 修改
    @RequestMapping("/uplStaff")
    public String uplStaff(String staff_name, String staff_sex, Integer staff_department, Integer staff_position,
                           String staff_cell_phone_number, String staff_id_number, Integer staff_id){
       staffService.uplStaff(staff_name,staff_sex,staff_department,staff_position,staff_cell_phone_number,staff_id_number,staff_id);  // 获取页面上的值
        return "staff/staff";
    }

    // 删除
    @RequestMapping("/delStaff")
    public String delPosition(Integer staff_id){
        staffService.delStaff(staff_id);// 获取页面上的值
        return "staff/staff";
    }
}
